package leetcode;

import javax.swing.tree.TreeNode;

public class Solution4 {
    //翻转一颗二叉树
    public TreeNode invertTree(TreeNode root) {
        if(root == null){
            return null;
        }
        //前序遍历 和 后续遍历均可
        invertTree(root.left);
        invertTree(root.right);
        swapChildren(root);
        return root;
    }

    //交换逻辑
    private void swapChildren(TreeNode root){

        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;
    }
}
